package com.example.administrator.qimo3no74.category.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.qimo3no74.R;
import com.example.administrator.qimo3no74.category.HotBrandsIcon;
import com.example.administrator.qimo3no74.category.HotBrandsIconAdapter;
import com.example.administrator.qimo3no74.category.HotCategoryIcon;
import com.example.administrator.qimo3no74.category.HotCategoryIconAdapter;
import com.example.administrator.qimo3no74.category.RecommendIcon;
import com.example.administrator.qimo3no74.category.RecommendIconAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class OneFragment extends Fragment {

    private List<RecommendIcon> recommendIcons = new ArrayList<>();
    private List<HotCategoryIcon> hotCategoryIcons = new ArrayList<>();
    private List<HotBrandsIcon> hotBrandsIcons = new ArrayList<>();
    private TextView oneTextViewRealTimeSell;
    private TextView oneTextViewHotCategorySell;
    private TextView oneTextViewHotBrandsSell;

    public OneFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_one, container, false);

        //初始化
        oneTextViewRealTimeSell = view.findViewById(R.id.oneTextViewRealTimeSell);
        oneTextViewHotCategorySell = view.findViewById(R.id.oneTextViewHotCategorySell);
        oneTextViewHotBrandsSell = view.findViewById(R.id.oneTextViewHotBrandsSell);

        //实时分类推荐
        initRecommend();
        actionRecommend(view);

        //热门类目
        initHotCategory();
        actionHotCategory(view);

        //热门品牌
        actionHotBrands(view);
        initHotBrands();

        //点击事件
        onclickAction();

        return view;
    }

    private void onclickAction() {
        oneTextViewRealTimeSell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(),"还有更多的实时分类推荐哦",Toast.LENGTH_SHORT).show();
            }
        });
        oneTextViewHotCategorySell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(),"还有更多的热门类目哦",Toast.LENGTH_SHORT).show();
            }
        });
        oneTextViewHotBrandsSell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(),"还有更多的热门品牌哦",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void actionHotBrands(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.oneRecyclerView3);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),3);
        recyclerView.setLayoutManager(layoutManager);
        HotBrandsIconAdapter adapter = new HotBrandsIconAdapter(hotBrandsIcons);
        recyclerView.setAdapter(adapter);

    }

    private void initHotBrands() {
        hotBrandsIcons.add(new HotBrandsIcon("华为",R.drawable.hua_wei));
        hotBrandsIcons.add(new HotBrandsIcon("小米",R.drawable.xiao_mi));
        hotBrandsIcons.add(new HotBrandsIcon("VIVO",R.drawable.vivo));
        hotBrandsIcons.add(new HotBrandsIcon("OPPO",R.drawable.oppo));
        hotBrandsIcons.add(new HotBrandsIcon("惠普",R.drawable.hui_pu));
        hotBrandsIcons.add(new HotBrandsIcon("联想",R.drawable.lian_xiang));

    }

    private void actionHotCategory(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.oneRecyclerView2);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),3);
        recyclerView.setLayoutManager(layoutManager);
        HotCategoryIconAdapter adapter = new HotCategoryIconAdapter(hotCategoryIcons);
        recyclerView.setAdapter(adapter);

    }

    private void initHotCategory() {
        hotCategoryIcons.add(new HotCategoryIcon("手机",R.drawable.vivo_shouji));
        hotCategoryIcons.add(new HotCategoryIcon("手机保护",R.drawable.shouji_ke));
        hotCategoryIcons.add(new HotCategoryIcon("笔记本电脑",R.drawable.bi_ji_ben));
        hotCategoryIcons.add(new HotCategoryIcon("平板电脑",R.drawable.ping_ban));
        hotCategoryIcons.add(new HotCategoryIcon("移动电源",R.drawable.dian_bao));
        hotCategoryIcons.add(new HotCategoryIcon("智能手环",R.drawable.shou_huan));

    }

    private void actionRecommend(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.oneRecyclerView1);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),3);
        recyclerView.setLayoutManager(layoutManager);
        RecommendIconAdapter adapter = new RecommendIconAdapter(recommendIcons);
        recyclerView.setAdapter(adapter);

    }

    private void initRecommend() {
        recommendIcons.add(new RecommendIcon("普通U盘",R.drawable.u_pan));
        recommendIcons.add(new RecommendIcon("显卡",R.drawable.xian_ka));
        recommendIcons.add(new RecommendIcon("笔记本电脑",R.drawable.bi_ji_ben));
        recommendIcons.add(new RecommendIcon("手机保护套",R.drawable.shouji_ke));
        recommendIcons.add(new RecommendIcon("手机数据线",R.drawable.shuju_xian));
        recommendIcons.add(new RecommendIcon("手写笔",R.drawable.shouxie_bi));

    }

}
